#!/bin/sh
###################
. /etc/profile
. ~/.bash_profile
##################



# Remote Siebel Path
ftpServer=172.31.0.79
ftpUserName=siebel
ftpPassword=siebel
ftpRemoteDir="/siebel/app/siebel/siebsrvr/objects"

# Local Siebel Path
ftpLocalDir="/siebel/app/siebsrvr/objects"

# Restart Shell 
startcmd="/home/siebel/scripts/startsrvr.sh"
stopcmd="/home/siebel/scripts/stopsrvr.sh"
currentDate=$(date +%Y%m%d)

echo 
echo "#-------------  Start Migrate Siebel Test To Prod At :`date +"%Y-%m-%d %H:%M:%S"` ----------#"


if [ ! -f "${ftpRemoteDir}/chs/siebel_sia.srf.${currentDate}" ]
then
        # backup srf
        echo "# Backup SRF.... `date +"%Y-%m-%d %H:%M:%S"`"
        echo "#"

        cp ${ftpLocalDir}/chs/siebel_sia.srf $ftpLocalDir/chs/siebel_sia.srf.${currentDate}
        cp ${ftpLocalDir}/enu/siebel_sia.srf ${ftpLocalDir}/enu/siebel_sia.srf.${currentDate}

        echo "# Backup Completed! `date +"%Y-%m-%d %H:%M:%S"`"
        echo "#"

fi

#lftp <<_LABEL
#set ftp:passive off
#open $ftpServer
#user $ftpUserName $ftpPassword
#cd $ftpRemoteDir/chs/
#lcd $ftpLocalDir/chs/
#mget siebel_sia.srf
#close
#bye
#_LABEL

sftp siebel@172.31.0.79:/siebel/app/siebel/siebsrvr/objects/chs/siebel_sia.srf ${ftpLocalDir}/chs/siebel_sia.srf

echo "# CHS SRF Download Completed . `date +"%Y-%m-%d %H:%M:%S"`"
echo "#"

#lftp <<_LABEL
#set ftp:passive off
#open $ftpServer
#user $ftpUserName $ftpPassword
#cd $ftpRemoteDir/enu/ 
#lcd $ftpLocalDir/enu/
#mget siebel_sia.srf
#close
#bye
#_LABEL

sftp siebel@172.31.0.79:/siebel/app/siebel/siebsrvr/objects/enu/siebel_sia.srf ${ftpLocalDir}/enu/siebel_sia.srf

echo "# ENU SRF Download Completed . `date +"%Y-%m-%d %H:%M:%S"`"
echo "#"

# stop server
echo "# Restart Server `date +"%Y-%m-%d %H:%M:%S"`"
echo "#"
${stopcmd}

sleep 3

# start server 
${startcmd}
echo "# Restart Server OK. `date +"%Y-%m-%d %H:%M:%S"`"
echo "#"

echo "#-------------  End   Migrate Siebel Test To Prod At :`date +"%Y-%m-%d %H:%M:%S"` ----------#"
echo 
